package cxydmmszl.chapter08.t136;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * <li style="color: red;">Prob</li>
 * 不包含本位置值的累乘数组
 * <li style="color: red;">Desc</li>
 * 输入描述：<br/>
 * 第一行有两个整数N, P。分别表示序列长度，模数(即输出的每个数需要对此取模)
 * 接下来一行N个整数表示数组内的数<br/><br/>
 * 输出描述：<br/>
 * 输出N个整数表示答案
 * <li style="color: red;">Link</li> CD35
 *
 * @author habitplus
 * @since 2021-09-06 20:44
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] ss = bf.readLine().split(" ");
        int n = Integer.parseInt(ss[0]);
        int p = Integer.parseInt(ss[1]);

        int[] arr = new int[n];
        ss = bf.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(ss[i]);
        }
        bf.close();

        int[] ans = solve(arr, p);

        StringBuilder sb = new StringBuilder();
        for (int e : ans) {
            sb.append(e).append(" ");
        }
        System.out.println(sb.toString());
    }

    private static int[] solve(int[] arr, int mod) {
        if (arr == null || arr.length < 1) {
            return new int[0];
        }

        int n = arr.length;
        int[] res = new int[n];
        long t = 1L;

        res[n - 1] = 1;

        for (int i = n - 2; i >= 0; i--) {
            t = (t * arr[i + 1]) % mod;
            res[i] = (int) t;
        }

        t = 1L;
        for (int i = 1; i < n; i++) {
            t = (t * arr[i - 1]) % mod;
            res[i] = (int) ((res[i] * t) % mod);
        }

        return res;
    }
}
